package com.juli.school.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.juli.school.dao.entity.Gift;
import com.juli.school.dao.mapper.GiftMapper;
import com.juli.school.utils.core.model.CommonResp;
import com.juli.school.utils.core.model.PageResp;
import com.juli.school.utils.dao.base.Page;

/**
 * @Description: 积分换礼表
 * @author: wjp
 * @date: 2018年1月31日下午9:29:40
 */
@Service
public class GiftService {
	private static final Logger logger = LoggerFactory.getLogger(GiftService.class);
	@Resource
	GiftMapper giftMapper;

	/**
	 * @Description: 分页获取所有可兑换的积分礼品
	 * @author: wjp
	 * @date: 2018年1月31日下午9:45:46
	 */
	public CommonResp<PageResp<Gift>> listPage(Gift gift, Integer pageNo, Integer pageSize) {
		CommonResp<PageResp<Gift>> commonResp = new CommonResp<PageResp<Gift>>();
		try {
			gift.setIsActive(1);
			// 设置分页信息
			Page page = new Page();
			page.setCurrentPage(pageNo == null ? 0 : pageNo);
			page.setShowCount(pageSize == null ? 10 : pageSize);
			gift.setPage(page);
			List<Gift> listPage = giftMapper.listPage(gift);
			PageResp<Gift> pageResp = new PageResp<>();
			pageResp.setList(listPage);
			pageResp.setPage(page);
			commonResp.success();
			commonResp.setData(pageResp);
		} catch (Exception e) {
			logger.error("获取积分礼品列表发生异常", e);
			commonResp.exception("获取积分礼品列表发生异常");
		}

		return commonResp;
	}
}
